package dev.alm.java11boot276.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.java11boot276.entity.User;
import dev.alm.java11boot276.mapper.UserMapper;
import dev.alm.java11boot276.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User add(User user) {
        int insert = userMapper.insert(user);
        if (insert <= 0) {
            return null;
        }
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", user.getUsername());
        return userMapper.selectOne(wrapper);
    }

    @Override
    public List<User> list() {
        List<User> users = userMapper.selectList(null);
        return users;
    }
}
